package com.prolificinteractive.materialcalendarview;

import ohos.agp.components.AttrSet;
import ohos.agp.components.PageSlider;
import ohos.app.Context;
import ohos.multimodalinput.event.TouchEvent;

import com.prolificinteractive.materialcalendarview.ext.Logger2;

/**
 * Custom ViewPager that allows swiping to be disabled.
 *
 * @since 2021-07-14
 */
class CalendarPager extends PageSlider {

    private boolean pagingEnabled = true;

    public CalendarPager(final Context context) {
        this(context, null);
    }

    public CalendarPager(final Context context, final AttrSet attrs) {
        super(context, attrs);
//        setTouchEventListener(this);
    }

    /**
     * enable disable viewpager scroll
     *
     * @param pagingEnabled false to disable paging, true for paging (default)
     */
    public void setPagingEnabled(boolean pagingEnabled) {
        this.pagingEnabled = pagingEnabled;
        setSlidingPossible(pagingEnabled);
    }

    /**
     * isPagingEnabled
     *
     * @return is this viewpager allowed to page
     */
    public boolean isPagingEnabled() {
        return pagingEnabled;
    }

    public boolean onInterceptTouchEvent(TouchEvent ev) {
        return pagingEnabled;
    }

//    @Override
//    public boolean onTouchEvent(MotionEvent ev) {
//        return pagingEnabled && super.onTouchEvent(ev);
//    }

//    @Override
//    public boolean onTouchEvent(Component component, TouchEvent touchEvent) {
//        return pagingEnabled;
//    }

//    @Override
//    public boolean canScroll(int orientation) {
//        return pagingEnabled && super.canScroll(orientation);
//    }

//    @Override
//    public boolean canScrollVertically(int direction) {
//        /**
//         * disables scrolling vertically when paging disabled, fixes scrolling
//         * for nested {@link android.support.v4.view.ViewPager}
//         */
//        return pagingEnabled && super.canScrollVertically(direction);
//    }
//
//    @Override
//    public boolean canScrollHorizontally(int direction) {
//        /**
//         * disables scrolling horizontally when paging disabled, fixes scrolling
//         * for nested {@link android.support.v4.view.ViewPager}
//         */
//        return pagingEnabled && super.canScrollHorizontally(direction);
//    }
}
